package com.aaron.kjviewutils.widget;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import com.aaron.kjviewutils.BaseActivity;
import com.aaron.kjviewutils.R;
import com.aaron.kjviewutils.eventBus.EventBusMsg;
import com.aaron.kjviewutils.spinkit.PoponDismissListener;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by Aaron on 2017/3/6.
 */

public class MenuPopWin extends PopupWindow {

    private Context context;
    private Activity aty;

    public MenuPopWin(Context context, Activity aty)
    {
        this.context = context;
        this.aty = aty;
    }

    public
    void showUi (final EventBus eventBus)
    {
        View view = LayoutInflater.from ( context ).inflate (
                R.layout.pop_menu,
                null
        );
        RelativeLayout settingL = (RelativeLayout) view.findViewById(R.id.settingL);
        RelativeLayout shareL = (RelativeLayout) view.findViewById(R.id.shareL);
        RelativeLayout learnL = (RelativeLayout) view.findViewById(R.id.learnL);
        shareL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(null!=eventBus)
                {
                    dismissView();
                    eventBus.post(new EventBusMsg(EventBusMsg.EventBusType.MENU_SHARE));
                }
            }
        });
        // 设置SelectPicPopupWindow的View
        this.setContentView ( view );
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth (WindowManager.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight (WindowManager.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        BaseActivity.backgroundAlpha(aty, 0.4f);
    }

    public void dismissView()
    {
        setOnDismissListener ( new PoponDismissListener( aty ) );
        dismiss ();
    }
}
